﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_DinnerSendTotalSrhForm
 * 类型：       控制层
 * 功能说明：   生活管家-送菜单明细列表页面
 * 作者：       黄鑫
 * 创建日期：   2007/11/22
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.System.Validator;
using Shpm.System.Web.Control;
using log4net;
using Shpm.App.Input.Bean;
using Shpm.App.Input.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using Shpm.App.Commons.Utils;
using Shpm.App.Master.Dao;
using Shpm.App.Master.Bean;
using Shpm.App.Common.Bean;

public partial class App_Input_DinnerSendTotalSrhForm : System.Web.UI.Page
{
    // log
    protected static ILog log = LogManager.GetLogger(typeof(App_Input_DinnerSendTotalSrhForm));

    // page load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // 取得当前登录的职员id信息
            SysUserManager manager = new SysUserManager(Context);
            SysUserBean sysUserBean = manager.getSysUserBean();
            MstSysUserBean mstSysUserBean =
                sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
            MstEmployeeBean mstEmpBean =
                sysUserBean == null ? null : sysUserBean.getEmployeeBean();
            string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
            string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;
            this.ViewState["SEARCH_FLG"] = 0;
            DishDao dao = new DishDao();
            CommonDictionaryBean bean = new CommonDictionaryBean();

            // 用餐时间
            bean.Catalog = "M_DISH.DISH_TIME";
            IList lstTime = dao.FindByCatalog(bean);
            lstDishTime.DataSource = lstTime;
            lstDishTime.DataBind();
            this.btnPrint.Disabled = true;
            txtDinnerDate.Text = DateUtils.convertToString(DateTime.Today);

        }
    }

    // before render
    void Page_PreRender(object sender, EventArgs e)
    {
        if ("0".Equals(Convert.ToString(this.ViewState["SEARCH_FLG"])))
        {
            return;
        }
        // get current doctor responsibility members list
        BookFoodDao dao = new BookFoodDao();
        IList lstRst = null;
        DinnerSendBean bean = new DinnerSendBean();
        bean.DinnerDate2 = Convert.ToDateTime(this.ViewState["DINNER_DATE"]);
        bean.DishType = string.IsNullOrEmpty(Convert.ToString(this.ViewState["DINNER_TYPE"])) ? null : Convert.ToString(this.ViewState["DINNER_TYPE"]);
        lstRst = dao.ListDinnerSendTotal(bean);
        if (lstRst.Count == 0)
        {
            this.btnPrint.Disabled = true;
            ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0005").ToString();
        }
        else
        {
            this.btnPrint.Disabled = false;
            viewSrhRst.Visible = true;
            viewSrhRst.DataSource = lstRst;
            viewSrhRst.DataBind();
        }
    }

    // page index change
    protected void viewSrhRst_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        viewSrhRst.PageIndex = e.NewPageIndex;
    }

    // details click
    protected void viewSrhRst_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    }

    // adjust bind data
    protected void viewSrhRst_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    }
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        ComValidateChecker vd = new ComValidateChecker();
        vd.CheckItems.Add(new CheckRequired(txtDinnerDate.Text, new ComMessage("E0082", "送菜日期")));
        vd.CheckItems.Add(new CheckDate(txtDinnerDate.Text, "yyyy/MM/dd", new ComMessage("E0037", "送菜日期")));
        if (!vd.DoValidator())
        {
            ((Design_MasterPage)this.Master).InfoMessage = vd.ErrorMessage;
            this.ViewState["SEARCH_FLG"] = "0";
           
            return;
        }
        else
        {
           
            this.ViewState["SEARCH_FLG"] = "1";
            this.ViewState["DINNER_DATE"] = txtDinnerDate.Text;
            this.ViewState["DINNER_TYPE"] = lstDishTime.SelectedValue;
        }

        this.hidDate.Value = Convert.ToString(ViewState["DINNER_DATE"]);
        this.hidTime.Value = Convert.ToString(ViewState["DINNER_TYPE"]);
    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        ComValidateChecker vd = new ComValidateChecker();
        vd.CheckItems.Add(new CheckRequired(txtDinnerDate.Text, new ComMessage("E0082", "送菜日期")));
        vd.CheckItems.Add(new CheckDate(txtDinnerDate.Text, "yyyy/MM/dd", new ComMessage("E0037", "送菜日期")));
        if (!vd.DoValidator())
        {
            ((Design_MasterPage)this.Master).InfoMessage = vd.ErrorMessage;
            this.ViewState["SEARCH_FLG"] = "0";
            return;
        }
        else
        {
            this.ViewState["SEARCH_FLG"] = "1";
            this.ViewState["DINNER_DATE"] = txtDinnerDate.Text;
            this.ViewState["DINNER_TYPE"] = lstDishTime.SelectedValue;
        }
    }
}
